package server.main.utils.mainutils;

import java.net.URL;

public class UrlUtils {

    /**
     * 解析路由 最后以/结尾
     * @return
     */
    public static String GetUrl(){
        URL url = UrlUtils.class.getClassLoader().getResource("");
        String str = url.getPath();
//        System.out.println("获取到的本地url"+str);


        String[] strl = str.split("/");
//        for(String str2:strl){
//            System.out.println(str2);
//        }
        int goal = 0;
        for(int i = 1 ;i < strl.length;i++){
            if(strl[i].equals("target")){
                goal = i;
            }
        }
//        System.out.println(strl.length+" "+goal);
        String str_goal = null;
        for(int i = 1;i < goal;i++){
            if(i == 1){
                str_goal =   strl[i] + "/";
            }
            else
                str_goal =  str_goal + strl[i] + "/";
        }
        System.out.println("本地项目根目录："+str_goal);
        return str_goal;
    }
     public static String GetMainUrl(){
        String str = get_user_dir();
        str = str + "/src/main/";
        return str;
    }
    public static String GetComUrl(){
        String str = get_user_dir();
        str = str + "/src/main/java/com/";
        return str;
    }
    public static String GetResourcesUrl(){
        String str = get_user_dir();
        str = str + "/src/main/resources/";
        return str;
    }
    public static String GetMvnPath(){

        return get_user_dir();
    }
    public static String GetJar(){

        return get_user_dir()+"/target/BloodTransfusionManagement-1.0-SNAPSHOT.jar";
    }
    public static String get_user_dir(){

        return System.getProperty("user.dir");

    }
}
